package com.swind.fast.modules.app.borrun.recruit.service.impl;

import com.swind.fast.modules.app.borrun.recruit.entity.BrRecruitProject;
import com.swind.fast.modules.app.borrun.recruit.mapper.BrRecruitProjectMapper;
import com.swind.fast.modules.app.borrun.recruit.service.IBrRecruitProjectService;
import com.swind.fast.modules.app.borrun.recruit.vo.BrRecruitProjectStatisticVo;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.Map;

/**
 * @Description: 博润阳光招募试验项目
 * @Author: swind
 * @Date:   2021-11-20
 * @Version: V1.0
 */
@Service
public class BrRecruitProjectServiceImpl extends ServiceImpl<BrRecruitProjectMapper, BrRecruitProject> implements IBrRecruitProjectService {

    public BrRecruitProjectStatisticVo getProjectStatistic() {
        QueryWrapper<BrRecruitProject> queryWrapper;

        queryWrapper = new QueryWrapper<BrRecruitProject>().select("status, count(id) as total").groupBy("status");
        List<Map<String, Object>> listMap = this.listMaps(queryWrapper);
        BrRecruitProjectStatisticVo statistic = new BrRecruitProjectStatisticVo("0", "0", "0", "0");

        for (Map<String, Object> item : listMap) {
            String status = String.valueOf(item.get("status"));
            String total = String.valueOf(item.get("total"));
            switch (status) {
                case "1" :
                    statistic.setOngoing(total);
                    break;
                case "2" :
                    statistic.setNotstarted(total);
                    break;
                case "3" :
                    statistic.setFinished(total);
                    break;
                case "4" :
                    statistic.setNotpublished(total);
                    break;
                default:
                    break;
            }
        }
        return statistic;
    }
}
